package com.orange.studio.dbk.activities;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.Button;

import com.meta.gui.quickaction.ActionItem;
import com.meta.gui.quickaction.QuickAction;
import com.orange.studio.dbk.R;
import com.orange.studio.dbk.adapters.ListSongAdapter;
import com.orange.studio.dbk.adapters.MainFragmentAdapter;


public class HomeActivity extends BaseActivity implements OnPageChangeListener {
	private ViewPager mViewPager=null;
	//private TabPageIndicator mIndicatior=null;
	
	private MainFragmentAdapter mAdapter=null;
	private List<Integer> mFavioriteIds=null;
	private List<Integer> mFavioriteRemovedIds=null;
	private static final String[] CONTENT = new String[] { "Appli", "Recommend", "Free"};
	private static final int[] ICONS = new int[] {
    	R.drawable.ic_launcher,
        R.drawable.ic_launcher,
        R.drawable.ic_launcher,
    };
	
	private Button mBtn=null;
	private ListSongAdapter mListSongAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setMainView(R.layout.activity_layout_home);
		initView();
        initListener();       
	}
	
	private void initView(){
    	mAdapter = new MainFragmentAdapter(getApplicationContext(),getSupportFragmentManager());
    	mViewPager = (ViewPager)findViewById(R.id.pager);
    	mViewPager.setAdapter(mAdapter);    	
    	mViewPager.setOnPageChangeListener(this);
    	mViewPager.setCurrentItem(0);
//    	mIndicatior=(TabPageIndicator)findViewById(R.id.indicator);
//    	mIndicatior.setViewPager(mViewPager);
//    	mIndicatior.setOnPageChangeListener(this);
    	
    	
    	//mBtn=(Button)findViewById(R.id.testbtn);
    	setFavioriteIds(new ArrayList<Integer>());
    	mFavioriteRemovedIds=new ArrayList<Integer>();    	
    }
    private void initListener(){
    	mViewPager.setOnPageChangeListener(this);
    	//mBtn.setOnClickListener(this);
    }
    @Override
    protected void onResume() {
    	super.onResume();    	
    }
	@Override
	public void onPageScrollStateChanged(int arg0) {
		
	}
	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		
	}
	
	private void switchCurrentItemByViewId(int resId) {
		switch (resId) {
		case R.id.menuLeft:
			mViewPager.setCurrentItem(0);
			break;
		case R.id.menuMiddle:
			mViewPager.setCurrentItem(1);
			break;
		case R.id.menuRight:
			mViewPager.setCurrentItem(2);
			break;
		default:
			break;
		}
	}
	@Override
	public void onPageSelected(int position) {
		switchCurrentItem(position);
		switchLayout(currentView);
		//mIndicatior.setCurrentItem(position);
		//Toast.makeText(getApplicationContext(), mAdapter.getCurrentFragment().getClass().getName(), Toast.LENGTH_LONG).show();
	}
	public void switchCurrentItem(int position) {
		switch (position) {
		case 0:
			currentView=R.id.menuLeft;
			mViewPager.setCurrentItem(0);
			break;
		case 1:
			currentView=R.id.menuMiddle;
			mViewPager.setCurrentItem(1);
			break;
		case 2:
			currentView=R.id.menuRight;
			mViewPager.setCurrentItem(2);
			break;
		default:
			break;
		}
	}
	private void showPopupMenu(View v) {
		QuickAction menu=new QuickAction(getApplicationContext());
		ActionItem item1=new ActionItem(111, "Menu 1");
		ActionItem item2=new ActionItem(111, "Menu 2");
		ActionItem item3=new ActionItem(111, "Menu 3");
		ActionItem item4=new ActionItem(111, "Menu 4");
		menu.addActionItem(item1);
		menu.addActionItem(item2);
		menu.addActionItem(item3);
		menu.addActionItem(item4);
		
		menu.show(v);
	}

	@Override
	public void onClick(View v) {
			int id=v.getId();
			switch (id) {
			
				default:
					super.onClick(v);
					break;
			}
			switchCurrentItemByViewId(currentView);
	}

	public List<Integer> getFavioriteIds() {
		return mFavioriteIds;
	}

	public void setFavioriteIds(List<Integer> mFavioriteIds) {
		this.mFavioriteIds = mFavioriteIds;
	}

	public List<Integer> getFavioriteRemovedIds() {
		return mFavioriteRemovedIds;
	}

	public void setFavioriteRemovedIds(List<Integer> mFavioriteRemovedIds) {
		this.mFavioriteRemovedIds = mFavioriteRemovedIds;
	}

	public ListSongAdapter getListSongAdapter() {
		return mListSongAdapter;
	}

	public void setListSongAdapter(ListSongAdapter mListSongAdapter) {
		this.mListSongAdapter = mListSongAdapter;
	}
	
}
